const initialState = {
  channels: [],
  myChannels: JSON.parse(localStorage.getItem("my_channel")) || [],
  articles: [],
  channelActiveKey: 0
}
export default function homeReducer(state = initialState, action) {
  switch (action.type) {
    // 保存可选频道
    case "GET_CHANNEL":
      return {
        ...state,
        channels: action.payload
      }
    // 保存新闻推荐
    case "GET_ARTICLES":
      return {
        ...state,
        articles: [...state.articles, ...action.payload.results],
        timestamp: action.payload.pre_timestamp
      }
    case "TOGGLE_TAB":
      return {
        ...state,
        channelActiveKey: action.payload
      }
    default:
      return state
  }
}
